package com.dycx.api.controller.manage.food;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.food.dto.GoodsTypeDTO;
import com.dycx.food.service.GoodsTypeFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/food/goodsType")
public class GoodsTypeFoodController {

    @Resource
    private GoodsTypeFoodService goodsTypeService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_TYPE, bizValue = "{#goodsTypeDto.id}")
    @PostMapping("/insert")
    public RestResponse<?> insert(@RequestBody @Valid GoodsTypeDTO goodsTypeDto) {
        return goodsTypeService.insert(goodsTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_TYPE, bizValue = "{#goodsTypeDto.id}")
    @PostMapping("/update")
    public RestResponse<?> update(@RequestBody @Valid GoodsTypeDTO goodsTypeDto) {
        return goodsTypeService.update(goodsTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_TYPE, bizValue = "{#goodsTypeId}")
    @GetMapping("/delete")
    public RestResponse<?> delete(int goodsTypeId) {
        return goodsTypeService.delete(goodsTypeId) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody GoodsTypeDTO dto) {
        return RestResponse.success(goodsTypeService.getPage(dto));
    }


    /**
     * 获取所有数据
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(goodsTypeService.getAllList());
    }

}
